package test.data_structure.linked_list;

import test.data_structure.queue.Queue;

public class LinkedListQueue<T> implements Queue<T> {

    private LinkedList<T> list;

    public LinkedListQueue() {
        list = new LinkedList<>();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public void enqueue(T data) {
        list.addLast(data);
    }

    @Override
    public T dequeue() {
        return list.removeFirst();
    }

    @Override
    public T getFront() {
        return list.getFirst();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Queue: front ");
        sb.append(list);
        sb.append(" tail");
        return sb.toString();
    }

    public static void main(String[] args) {
        LinkedListQueue<Integer> queue = new LinkedListQueue<>();
        for (int i = 0 ; i < 10 ; i ++) {
            queue.enqueue(i);
            System.out.println(queue);
            if (i % 3 == 2) {
                queue.dequeue();
                System.out.println(queue);
            }
        }
    }

}
